package com.example.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot.entity.LocaleInfo;
import com.example.springboot.mapper.LocaleInfoMapper;
import com.example.springboot.service.LocaleService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LocaleServiceImpl extends ServiceImpl<LocaleInfoMapper, LocaleInfo> implements LocaleService {
    @Override
    public List<LocaleInfo> listLocaleInfo(LocaleInfo localeInfo) {
        LambdaQueryWrapper<LocaleInfo> wrapper = Wrappers.lambdaQuery(localeInfo)
                .isNull(ObjectUtils.isEmpty(localeInfo.getLocaleId()), LocaleInfo::getLocaleId);
        List<LocaleInfo> list = this.list(wrapper);
        if (CollectionUtils.isNotEmpty(list)){
            list.forEach(info -> {
                LocaleInfo queryLocaleInfo = new LocaleInfo();
                queryLocaleInfo.setLocaleId(info.getId());
                List<LocaleInfo> localeInfoList = listLocaleInfo(queryLocaleInfo);
                info.setLocaleInfoList(localeInfoList);
            });
        }
        return list;
    }
}
